﻿using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;

namespace LujHosting.Internal;

internal record ServiceAutoConfig(
    RootDependencyCollector DepCollector,
    IList<HostConfigureExt.ServiceItem> InitList) {

  public void Configure(IList<Type> groupEx, IServiceCollection collection) {
    RootDependencyCollector.Result result = DepCollector.Collect(groupEx);

    foreach (HostConfigureExt.ServiceItem item in InitList) {
      //Console.WriteLine(item.Type.FullName);
      collection.AddSingleton(item.Type, item.Instance);
    }

    foreach (Type t in result.Concrete) {
      //Console.WriteLine(t.FullName);
      collection.AddSingleton(t);
    }

    foreach (RootDependencyCollector.Item item in result.Multi) {
      //Console.WriteLine(item);
      collection.AddSingleton(item.Service, item.Impl);
    }
  }
}
